<?php

require_once './include/common.inc.php';
require_once 'left.php';
require_once 'right.php';

$page_title = 'Acuity World WebShop';
$menu_id = 0;
$menu_str = PrintMenu();


// ѯpublish
$sql = "SELECT `id`, `name` FROM `pro_publisher`";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $publish_ary[$rs['id']] = $rs['name'];
}

// ѯauthor
$sql = "SELECT `id`, `name` FROM `pro_author`";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $author_ary[$rs['id']] = $rs['name'];
}


if (isset($_GET['category'])) {
    $category_id = intval($_GET['category']);
    if ($category_id == $SET_TRAINING_SCHEDULE_ID) {
        header("location:training_schedule.php");
        exit;
    }

    // ѯcategory
    $sql = "SELECT name FROM `pro_category` WHERE `id` = '$category_id'";
    $rs_ary = $db->get_one($sql);
    $product_title = $rs_ary['name'];

    // ѯµƷ
    $sql = "SELECT p.* FROM `pro_product` p, `pro_product_category` c WHERE p.`id` = c.`product_id` AND c.`category_id` = '$category_id' AND is_show GROUP BY p.`id` ORDER BY p.`orders` ASC";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
		if($rs["name"]!="")
        	$product_info_ary[$rs['id']] = $rs;
    }

} elseif ($_GET['type']) {
    $type_id = intval($_GET['type']);
    if ($type_id == $SET_COURSE_ID) {
        header("location:course.php");
        exit;
    }
    
    // ѯtype
    $sql = "SELECT name FROM `pro_type` WHERE `id` = '$type_id'";
    $rs_ary = $db->get_one($sql);
    $product_title = $rs_ary['name'];

    // ѯµƷ
    $sql = "SELECT p.* FROM `pro_product` p, `pro_product_type` t WHERE p.`id` = t.`product_id` AND t.`type_id` = '$type_id' AND is_show=1 GROUP BY p.`id` ORDER BY p.`orders` ASC";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
		if($rs["name"]!="")
			$product_info_ary[$rs['id']] = $rs;
    }

} elseif (isset($_GET['best_seller'])) {
    // ʾBest Seller    
    $product_title = 'Best Seller';
    
    // ѯµƷ
    $sql = "SELECT * FROM `pro_product` WHERE `is_best` = 1 AND is_show=1 ORDER BY `orders` ASC";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
		if($rs["name"]!="")
        	$product_info_ary[$rs['id']] = $rs;
    }

}

/*
* 
* $product_title ===> categorytypeƣBest Seller
* $product_info_ary ===> ѡƷ
* $publish_ary, $author_ary ===> publishauthor
*/

require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('products');
require_once PrintEot('right');
require_once PrintEot('footer');

?>